package com.tucc.hello.leetcode.no1_400.no1_200.no81_100.no100;

import com.tucc.hello.tree.Main;
import com.tucc.hello.tree.TreeNode;

import java.util.Arrays;

/**
 * @author tucc
 * @description todo
 * @package com.tucc.hello.leetcode
 * @date 2021/5/20
 **/
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        TreeNode p = Main.makeTree(Arrays.asList(1, null, 2, 3));
        TreeNode q = Main.makeTree(Arrays.asList(1, null, 2, 3));
        System.out.println(solution.isSameTree(p, q));
    }

    public boolean isSameTree(TreeNode p, TreeNode q) {
        if (p != null && q != null) {
            return p.val == q.val && isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
        }
        return p == q;
    }

}
